from docx import Document
from docx.shared import Pt
import os
import re
import shutil

root_dir = os.getcwd()
path = os.path.join(root_dir, "test")
repo_list = []
keyword = "Software:"

def get_name_version():
    file_list = os.listdir(path)
    doc_list = list(filter(lambda s: ".doc" in s or ".docx" in s, file_list))
    for file in doc_list:
        print(file)
        doc_name = file.split("(")[1].split(")")[0]
        print(doc_name)
        file_path = os.path.join(path, file)
        print(file_path)
        document = Document(file_path)
        all_paragraphs = document.paragraphs
        for paragraph in all_paragraphs:
            str1 = paragraph.text
            if str1.find(keyword) != -1:
                print(str1)
                doc_name = doc_name + " " +str1
                repo_list.append(doc_name)
                break
    out_file = os.path.join(root_dir, "name_version.txt")
    with open(out_file, "w") as file1:
        file1.writelines("\n".join(repo_list))

if __name__ == '__main__':
    get_name_version()
